package 深入反射机制.反射构造方法Constructor.反射机制调用构造方法.test01;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectTest01 {
    public static void main(String[] args) {
        try {
            Class c = Class.forName("test.Student");
            //获取有参数构造方法
            Constructor con = c.getDeclaredConstructor(int.class, String.class, int.class, boolean.class);
            Constructor con2 = c.getDeclaredConstructor(int.class,String.class);
            Object o1 = con.newInstance(33,"jojo",123,true);
            Object o2 = con2.newInstance(33,"上班族");
            System.out.println(o1);
            System.out.println(o2);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
